package com.jy.adscm.operation.aftersales.controller;


import com.baomidou.mybatisplus.plugins.Page;
import com.jy.adscm.annotation.AdscmLogger;
import com.jy.adscm.exception.AdscmSystemException;
import com.jy.adscm.operation.aftersales.bean.BaseQuery;
import com.jy.adscm.operation.aftersales.bean.ShAppVersion;
import com.jy.adscm.operation.aftersales.service.ShAppVersionService;
import com.jy.adscm.security.utils.Token;
import com.jy.adscm.support.SimpleCoreResponse;
import com.jy.adscm.utils.AdscmBaseUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;

/**
 * <p>
 * 售后程序版本控制 前端控制器
 * </p>
 *
 * @author zyl
 * @since 2020-06-15
 */
@RestController
@RequestMapping("/adscm/operation/aftersales/shAppVersion")
public class ShAppVersionController {
    @Autowired
    RedisTemplate<Object, Token> tokenRedisTemplate;
    @Autowired
    ShAppVersionService shAppVersionService;
    @RequestMapping("insert")
    public SimpleCoreResponse insert(@RequestBody ShAppVersion shAppVersion, HttpServletRequest request)throws AdscmSystemException {
        String tokenId = request.getParameter("tokenId");
        Token token = AdscmBaseUtils.getInstance().getTokenByTokenId(tokenId, tokenRedisTemplate);
        if(!AdscmBaseUtils.getInstance().isNotEmpty(token,null)){
            throw  new AdscmSystemException("token 是空的");
        }
        shAppVersion.setCreator(token.getUser().getId().toString());
        shAppVersion.setCreateTime(new Date());
        boolean insert = shAppVersionService.insert(shAppVersion);
        return  new SimpleCoreResponse("200","新增成功",insert);
    }
    @RequestMapping("select")
    public SimpleCoreResponse select(@RequestBody BaseQuery baseQuery, HttpServletRequest request)throws AdscmSystemException {
        String tokenId = request.getParameter("tokenId");
        Token token = AdscmBaseUtils.getInstance().getTokenByTokenId(tokenId, tokenRedisTemplate);
        Page<ShAppVersion> page = shAppVersionService.select(baseQuery);
        return  new SimpleCoreResponse("200","新增成功",page);
    }


}

